package com.we823.cms.repository.service.beetl.tag;

import java.util.List;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.we823.cms.model.extension.Brand;
import com.we823.cms.repository.service.extension.BrandService;

import javax.annotation.Resource;

@Service("cms_brands")
@Scope("prototype")
public class BrandListTag extends AbstractListTag {

	private static final String PARAM_SHOW_INDEX = "show_index";

	private @Resource BrandService brandService;

	@Override
	public void execute() {
		int showIndex = getParam(PARAM_SHOW_INDEX, -1);
		List<Brand> brandModels = null;
		if (showIndex==-1) {
			if(pageRequest==null){
				brandModels = brandService.findAll(sort);
			}else{
				PageInfo<Brand> brandPage = brandService.findAll(pageRequest);
				if(brandPage!=null){
					brandModels = brandPage.getList();
				}
			}
		}else {
			if(pageRequest==null){
				brandModels = brandService.findByShowIndex(showIndex,sort);
			}else{
				PageInfo<Brand> brandPage = brandService.findByShowIndex(showIndex,pageRequest);
				if(brandPage!=null){
					brandModels = brandPage.getList();
				}
			}
		}

		this.binds(brandModels);
	}
}
